<template>
    <div>
        <div class="container">
            <div class="common-title-flex">
                <div class="common-title-div"></div>
                <div class="common-title-text">数据筛选</div>
            </div>
            <el-form ref="searchObj" :inline="true" :model="searchObj" label-width="80px" style="margin-bottom:-30px;margin-top:1rem;">
                    <el-form-item label="警员名称">
                        <el-input v-model="searchObj.policeName" placeholder="请输入警员名称" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="所属地区">
                        <el-select v-model="searchObj.area" placeholder="请选择">
                            <el-option v-for="item in areaList" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="警员级别">
                        <el-select v-model="searchObj.policeLevel" placeholder="请选择">
                            <el-option v-for="item in policeLevelList" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item style="margin-left:2rem;">
                        <el-button type="primary" icon="el-icon-search" @click="query">查询</el-button>
                        <el-button @click="reset" icon="el-icon-refresh">重置</el-button>
                    </el-form-item>
            </el-form>
        </div>
        <div class="container" style="margin-top:1rem;">
            <div class="common-list-class">
                <div style="display:flex;">
                    <div class="common-title-div"></div>
                    <div class="common-title-text">查询结果</div>
                </div>
                <div style="display:flex;">
                    <el-button type="primary" style="height:32px;" icon="el-icon-upload">模版下载</el-button>
                    <el-upload
                    class="upload-file"
                    :headers="uploadHeader"
                    :before-upload="beforeUpload"
                    :action="uploadUrl"
                    :on-success="uploadSucess"
                    :on-error="uploadError"
                    :on-progress="uploadProgress"
                    :show-file-list="false">
                        <el-button type="primary" icon="el-icon-download">批量导入</el-button>
                    </el-upload>
                    <el-button type="primary" style="height:32px;" icon="el-icon-upload2">批量导出</el-button>
                    <el-button type="primary" style="height:32px;" icon="el-icon-circle-plus-outline" @click="addPolice">添加</el-button>
                </div>
            </div>
            <!-- 查询列表 -->
            <el-table :data="tableData" size="mini" style="width: 100%;height:450px;margin-top:10px;margin-bottom:10px;" max-height="450" border>
                <el-table-column type="index" label="序号" width="50" align="center">
                </el-table-column>
                <el-table-column prop="policeName" label="警员姓名" width="100"  show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="phone" label="手机号码" width="130"  show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="policeCode" label="警员警号" width="100" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="department" label="所属部门" width="100" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="station" label="当前岗位" width="100" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="belong" label="来源" width="100" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" width="200" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="createMan" label="创建人" width="100" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="status" label="状态" width="100"  show-overflow-tooltip>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="450" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" icon="el-icon-edit" @click="editClick(scope.row)">修改</el-button>
                        <el-button type="primary" size="mini" icon="el-icon-tickets" @click="detailsClick(scope.row)">详情</el-button>
                        <el-button type="success" size="mini" icon="el-icon-video-play" @click="startClick(scope.row)">启动</el-button>
                        <el-button type="danger" size="mini" icon="el-icon-remove" @click="forbidClick(scope.row)">禁用</el-button>
                        <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteClick(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-row type="flex" justify="end">
                    <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="pageSizes"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                    </el-pagination>
            </el-row>
        </div>
        <!-- 新增警员 和修改警员-->
        <el-dialog :title="isEditTitle" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="newaddFlag" width="50%" :before-close="handleClose" center>
            <el-form ref="inputObj" :model="inputObj" label-width="100px" :rules="rules">
                    <el-form-item label="登录账号" prop="username">
                        <el-input v-model="inputObj.username" placeholder="请输入登录账号" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="登录密码" prop="userpwd">
                        <el-input v-model="inputObj.userpwd" placeholder="请输入登录密码" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="警员姓名" prop="name">
                        <el-input v-model="inputObj.name" placeholder="请输入警员姓名" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="警员警号" prop="code">
                        <el-input v-model="inputObj.code" placeholder="请输入警员警号" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码" prop="phone">
                        <el-input v-model="inputObj.phone" placeholder="请输入手机号码" clearable ></el-input>
                    </el-form-item>
                    <el-form-item label="所属责任区" prop="area">
                        <el-select v-model="inputObj.area" multiple placeholder="请选择所属责任区" style="width:100%;">
                            <el-option
                            v-for="item in selfAreaList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属部门" prop="apartment">
                        <el-select v-model="inputObj.apartment" placeholder="请选择所属部门" style="width:100%;">
                            <el-option
                            v-for="item in apartmentList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="当前岗位" prop="currentPosition">
                        <el-select v-model="inputObj.currentPosition" placeholder="请选择当前岗位" style="width:100%;">
                            <el-option
                            v-for="item in currentPositionList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="座机/分机" prop="telephone">
                        <el-input v-model="inputObj.telephone" placeholder="请输入座机/分机" clearable ></el-input>
                    </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submit">提 交</el-button>
                <el-button @click="cancel">取 消</el-button>
            </span>
        </el-dialog>
        <!-- 警员详情 -->
        <el-dialog title="警员详情" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="detailsFlag" width="40%" :before-close="detailsClose" center>
            <el-row type="flex" justify="center">
                <el-col :span="4" class="bold-class">登录账号：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.username}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">登录密码：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.userpwd}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">警员姓名：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.name}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">警员警号：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.code}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">手机号码：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.phone}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">所属责任区：</el-col>
                <el-col :span="15">
                 <el-tag
                    style="margin:1px;"
                    v-for="item in detailsObj.area"
                    :key="item.id"
                    effect="plain">
                    {{ item.label }}
                </el-tag>
                </el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">所属部门：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.apartment}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">当前岗位：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.currentPosition}}</el-col>
            </el-row>
            <el-row type="flex" justify="center" style="margin-top:0.5rem;">
                <el-col :span="4" class="bold-class">座机/分机：</el-col>
                <el-col :span="15" class="grey-class">{{detailsObj.telephone}}</el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button type="danger" @click="detailsClose">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import mixin from '@/mixin/mixin.js'; 
    export default {
        name: 'taskList',
        mixins: [mixin],
        data(){
            return {
                uploadHeader:{
                  token:'1244567788'  
                },
                uploadUrl:'https://jsonplaceholder.typicode.com/posts/',
                rules:{
                    username: [
                        { required: true, message: '请输入登录账号', trigger: 'blur' }
                    ],
                    userpwd: [
                        { required: true, message: '请输入登录密码', trigger: 'blur' }
                    ],
                    name: [
                        { required: true, message: '请输入警员姓名', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输入警员警号', trigger: 'blur' }
                    ],
                    phone: [
                        { required: true, message: '请输入手机号码', trigger: 'blur' }
                    ],
                    area: [
                        { required: true, message: '请选择所属责任区', trigger: 'change' }
                    ],
                    apartment: [
                        { required: true, message: '请选择所属部门', trigger: 'change' }
                    ],
                    currentPosition:[
                        { required: true, message: '请选择当前岗位', trigger: 'change' }
                    ],
                },
                detailsObj:{
                    username:'12321123',
                    userpwd:'123',
                    name:'张三',
                    code:'123001',
                    phone:'1356454545',
                    area:[{
                        id:'1',
                        label:'六合区'
                    },{
                        id:'2',
                        label:'浦口区'
                    },{
                        id:'3',
                        label:'建业区'
                    },{
                        id:'4',
                        label:'大厂区'
                    },{
                        id:'5',
                        label:'秦淮区'
                    },{
                        id:'6',
                        label:'江宁区'
                    },{
                        id:'7',
                        label:'雨花台区'
                    },{
                        id:'8',
                        label:'溧水区'
                    },{
                        id:'9',
                        label:'高淳区'
                    }],
                    apartment:'部门22',
                    currentPosition:'当前位置11',
                    telephone:'025-21321312'
                },
                inputObj:{
                    username:'',
                    userpwd:'',
                    name:'',
                    code:'',
                    phone:'',
                    area:[],
                    apartment:'',
                    currentPosition:'',
                    telephone:''
                },
                detailsFlag:false,
                isEditTitle:'',
                newaddFlag:false,
                pageSizes:[10, 15, 50, 100],
                pagesize:10,
                total:10,
                currentPage:1,
                tableData: [{
                    policeName: '张警官',
                    phone: '13920003394',
                    policeCode: '1230000',
                    department:'部门1',
                    station:'岗位1',
                    belong:'手动创建',
                    createTime:'2020-12-20',
                    createMan:'张三',
                    status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    },{
                        policeName: '张警官',
                        phone: '13920003394',
                        policeCode: '1230000',
                        department:'部门1',
                        station:'岗位1',
                        belong:'手动创建',
                        createTime:'2020-12-20',
                        createMan:'张三',
                        status:'已禁用'
                    }],
                searchObj:{
                    policeName:'',
                    area:'',
                    policeLevel:''
                },
                currentPositionList:[{
                    value:'1',
                    label:'当前岗位1',
                    },{
                        value:'2',
                        label:'当前岗位2',
                    },{
                        value:'3',
                        label:'当前岗位3',
                    }],
                apartmentList:[{
                        value:'1',
                        label:'部门1',
                    },{
                        value:'2',
                        label:'部门2',
                    },{
                        value:'3',
                        label:'部门3',
                    }],
                    selfAreaList:[{
                        value:'1',
                        label:'玄武区',
                    },{
                        value:'2',
                        label:'秦淮区',
                    },{
                        value:'3',
                        label:'建邺区',
                    },{
                        value:'4',
                        label:'鼓楼区',
                    },{
                        value:'5',
                        label:'浦口区',
                    },{
                        value:'6',
                        label:'栖霞区',
                    },{
                        value:'7',
                        label:'雨花台区',
                    },{
                        value:'8',
                        label:'江宁区',
                    },{
                        value:'9',
                        label:'六合区',
                    },{
                        value:'10',
                        label:'溧水区',
                    },{
                        value:'11',
                        label:'高淳区',
                    }],
                areaList:[{
                        value:'1',
                        label:'所属区域1',
                    },{
                        value:'2',
                        label:'所属区域2',
                    },{
                        value:'3',
                        label:'所属区域3',
                    }],
                policeLevelList:[{
                        value:'1',
                        label:'级别1',
                    },{
                        value:'2',
                        label:'级别2',
                    },{
                        value:'3',
                        label:'级别3',
                    }]
            }
        },
        methods: {
            beforeUpload(file){
                this.showLoading('导入中')
            },
            uploadProgress(event, file, fileList){
                this.videoUploadPercent = file.percentage.toFixed(0)+"%";
                console.log('event--------',event)
                console.log('file--------',file)
                console.log('fileList--------',fileList)
            },
            uploadSucess(response){
                this.$message({
                    message:'导入成功！',
                    type:'success'
                })
                this.hideLoading();
                console.log('response------',response)
            },
            uploadError(error){
                 this.$message({
                    message:'导入失败！',
                    type:'error'
                })
                this.hideLoading();
                console.log('error-----',error)
            },
            // 新建确认和修改确认
            submit(){
                // this.$axios({
                //     method: 'get',
                //     url: `${this.requestUrl}`,
                //     headers:{
                //         token:this.requestToken     
                //     },
                //     data: params,
                //     params: params
                // })
            },
            // 取消点击
            cancel(){
                this.newaddFlag = false;
                this.inputObj = {
                    username:'',
                    userpwd:'',
                    name:'',
                    code:'',
                    phone:'',
                    area:[],
                    apartment:'',
                    currentPosition:'',
                    telephone:''
                };
                this.$refs["inputObj"].resetFields();
            },
            // 取消点击
            handleClose(){
                this.cancel();
            },
            // 点击分页当前页多少数据
            handleSizeChange(val){
                this.pagesize = val;
            },
            // 点击分页页数
            handleCurrentChange(val){
                this.currentPage = val;
            },
            // 查询
            query() {
                console.log(this.searchObj);
            },
            //  重置
            reset(){
                this.searchObj={
                    policeName:'',
                    area:'',
                    policeLevel:''
                }
            },
            // 删除
            deleteClick(row){
                this.$confirm('请确认是否删除该警员?', '删除', {
                    confirmButtonText: '是',
                    cancelButtonText: '否',
                    }).then(() => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });          
                    });
            },
            // 禁用
            forbidClick(){
                this.$confirm('请确认是否禁用该警员?', '禁用', {
                    confirmButtonText: '是',
                    cancelButtonText: '否',
                }).then(() => {
                this.$message({
                    type: 'success',
                    message: '禁用成功!'
                });
                }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消禁用'
                });          
                });
            },
            // 新增
            addPolice(){
                this.newaddFlag = true;
                this.isEditTitle = '新增警员';
            },
            // 详情
            detailsClick(row){
                this.detailsFlag = true;
            },
            // 详情关闭
            detailsClose(){
                this.detailsFlag = false;
            },
            // 修改
            editClick(){
                this.newaddFlag = true;
                this.isEditTitle = '修改警员';
                this.inputObj = {
                    username:'张三',
                    userpwd:'123',
                    name:'张警官',
                    code:'12322',
                    phone:'123456733',
                    area:['六合区','浦口区','建邺区'],
                    apartment:'请问我去',
                    currentPosition:'当前位置111',
                    telephone:'2132312'
                };
            }
        }
    }
</script>
<style scoped>
/* .el-switch__core:after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    border-radius: 100%;
    transition: all .3s;
    width: 16px;
    height: 16px;
    background-color: #fff;
  }
  .el-switch.is-checked .el-switch__core:after {
    left: 100%;
    margin-left: -17px;
  } */
  .common-title-flex{
      display:flex;
  }
  .common-title-div{
      width:3px;
      height:18px;
      background-color:#368af7;
      margin-top:2px;
  }
  .common-title-text{
      margin-left:4px;
  }
  .common-list-class{
      display:flex;
      justify-content:space-between;
      margin-top:-10px;
  }
  .grey-class{
      color: grey;
      font-size: 14px;
  }
  .bold-class{
      font-weight: bold;
  }
  .upload-file >>> .el-upload--text{
      border:none;
      width: 100px;
      height: 36px;
  }
</style>>